package com.alibaba.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component;

import java.lang.annotation.*;
import java.lang.reflect.Field;

/**
 * @Author: zhuangzhiwen
 * @Date: 2021/8/17
 */

//@Component
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @Fan_she_m("db_table")
public class User {
        @Fan_she_f("1年级")
    public String clazz;

        @Fan_she_f("zzw")
    private String name;

        @Fan_she_f("18")
    private int age;

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void test(){
        System.out.println("初始化·之后");
    }
}


@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@interface Fan_she_m{
        String value();
}

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@interface Fan_she_f{
    String value();
}


class T{
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException {
        Class c1 = Class.forName("com.alibaba.entity.User");
        if(c1.isAnnotationPresent(Fan_she_m.class)){
            for (Annotation annotation : c1.getAnnotations()) {
                System.out.println(annotation);
            }

            Fan_she_m annotation = (Fan_she_m) c1.getAnnotation(Fan_she_m.class);
            String value = annotation.value();
            System.out.println(value);

        }

        Field clazz = c1.getDeclaredField("clazz");
        if(clazz.isAnnotationPresent(Fan_she_f.class)){
            Fan_she_f annotation = clazz.getAnnotation(Fan_she_f.class);
            System.out.println(annotation.value());
            System.out.println(annotation.value());
            System.out.println(annotation.value());
        }

    }
}



